From: Michael Dale Date: Fri, 14 Aug 2009 18:01:05 +0000 (+0000) Subject: * added curl option support for get requests X-Git-Tag: 1.31.0-rc.0~40305 X-Git-Url: http://git.cyclocoop.org/%22.%24info%5B?a=commitdiff_plain;h=7049cbd76e262a87f1fdef5a545f8913a4be8b31;p=lhc%2Fweb%2Fwiklou.git * added curl option support for get requests --- diff --git a/includes/HttpFunctions.php b/includes/HttpFunctions.php index 5bb56720af..266d2a18ba 100644 --- a/includes/HttpFunctions.php +++ b/includes/HttpFunctions.php @@ -27,7 +27,8 @@ class Http { /** * Simple wrapper for Http::request( 'GET' ) */ - public static function get( $url, $timeout = false ) { + public static function get( $url, $timeout = false, $opts = array() ) { + global $wgSyncHTTPTimeout; $opts = array(); if( $timeout ) $opts['timeout'] = $timeout; @@ -224,7 +225,6 @@ class Http { $printer->execute(); $apiUploadResult = ob_get_clean(); - //wfDebug( __METHOD__ . "\n\n got api result:: $apiUploadResult \n" ); // the status updates runner will grab the result form the session: $sd['apiUploadResult'] = $apiUploadResult; } @@ -278,7 +278,13 @@ class Http { class HttpRequest { var $target_file_path; var $upload_session_key; - + var $supportedCurlOpts = array( + 'CURLOPT_SSL_VERIFYHOST', + 'CURLOPT_CAINFO', + 'CURLOPT_COOKIE', + 'CURLOPT_FOLLOWLOCATION', + 'CURLOPT_FAILONERROR' + ); function __construct( $url, $opt ){ global $wgSyncHTTPTimeout; // double check that it's a valid url: @@ -286,12 +292,25 @@ class HttpRequest { // set the timeout to default sync timeout (unless the timeout option is provided) $this->timeout = ( isset( $opt['timeout'] ) ) ? $opt['timeout'] : $wgSyncHTTPTimeout; + //check special key default + if($timeout == 'default'){ + $opts['timeout'] = $wgSyncHTTPTimeout; + } + $this->method = ( isset( $opt['method'] ) ) ? $opt['method'] : 'GET'; $this->target_file_path = ( isset( $opt['target_file_path'] ) ) ? $opt['target_file_path'] : false; $this->upload_session_key = ( isset( $opt['upload_session_key'] ) ) ? $opt['upload_session_key'] : false; $this->headers_only = ( isset( $opt['headers_only'] ) ) ? $opt['headers_only'] : false; $this->do_close_session_update = isset( $opt['do_close_session_update'] ); $this->postData = isset( $opt['postdata'] ) ? $opt['postdata'] : ''; + + $this->curlOpt = array(); + //check for some curl options: + foreach($this->supportedCurlOpts as $curlOpt){ + if(isset($opt[ $curlOpt ])){ + $this->curlOpt[$curlOpt] = $opt[ $curlOpt ]; + } + } } /** @@ -331,6 +350,11 @@ class HttpRequest { curl_setopt( $c, CURLOPT_TIMEOUT, $this->timeout ); curl_setopt( $c, CURLOPT_USERAGENT, Http::userAgent() ); + //set any curl specific opts: + foreach($this->curlOpt as $optKey => $optVal){ + curl_setopt($c, constant( $optKey ), $optVal); + } + if ( $this->headers_only ) { curl_setopt( $c, CURLOPT_NOBODY, true ); curl_setopt( $c, CURLOPT_HEADER, true );